from flask import Flask ,render_template,jsonify
import utils
cov = Flask(__name__)

@cov.route('/')
def hello_world():
    return render_template("main.html")

@cov.route('/r2', methods=['get', 'post'])
def get_r2_data():
    data = utils.get_r2_data()  # 格式 ['民警抗疫一线奋战16天牺牲1037364','四川再派两批医疗队1537382',]
    return jsonify({"kws": data})


@cov.route('/r1', methods=['get', 'post'])
def get_r1_data():
    data = utils.get_r1_data()
    return jsonify({
        'name': data[0],
        'value': data[1]
    })

@cov.route('/l1', methods=['get', 'post'])
def get_l1_data():
    data = utils.get_l1_data()
    # print(data)
    return jsonify({
        "day": data[0],
        "new_local": data[1],
        "asymptomatic": data[2]
    })
@cov.route("/l2", methods=['get','post'])
def get_l2_data():
    data = utils.get_l2_data()
    # end_update_time, province, city, address, type
    details = []
    risk = []
    end_update_time = data[0][0]
    for a,b,c,d,e in data:
        risk.append(e)
        details.append(f"{b}\t{c}\t{d}")
    return jsonify({"update_time": end_update_time, "details": details, "risk": risk})

@cov.route('/c1', methods=['get','post'])
def get_c1_data():
    data = utils.get_c1_data()
    return jsonify({"confirmed": str(data[0]), "overseasInput": str(data[1]), "cured": str(data[2]), "died": str(data[3]), "curConfirm": str(data[4]), "curOverseasInput": str(data[5]), "curLocalConfirm": str(data[6]), "asymptomaticLocal": str(data[7])})

@cov.route("/c2", methods=['get','post'])
def get_c2_data():
    res = utils.get_c2_data()
    return jsonify({'data': res})


if __name__ == '__main__':
    cov.run(host="0.0.0.0",port=5000,debug=Flask)